package org.abc.fund.repository.factorRepository;

import org.abc.fund.entity.factorEntity.DerivedFactorComponent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 衍生因子组件Repository
 */
@Repository
public interface DerivedFactorComponentRepository extends JpaRepository<DerivedFactorComponent, Long> {
//
//    /**
//     * 根据衍生因子ID查找组件列表
//     */
//    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.id = :derivedFactorId ORDER BY dfc.sortOrder ASC")
//    List<DerivedFactorComponent> findByDerivedFactorIdOrderBySortOrderAsc(@Param("derivedFactorId") Long derivedFactorId);
//
//    /**
//     * 根据衍生因子ID查找组件列表（简化版本）
//     */
//    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.id = :derivedFactorId")
//    List<DerivedFactorComponent> findByDerivedFactorId(@Param("derivedFactorId") Long derivedFactorId);
//    /**
//     * 根据衍生因子代码查找组件列表
//     */
//    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.factorCode = :derivedFactorCode")
//    List<DerivedFactorComponent> findByDerivedFactorCode(@Param("derivedFactorId") String derivedFactorCode);
//
//    /**
//     * 根据输入因子ID查找组件列表
//     */
//    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.inputFactor.id = :inputFactorId")
//    List<DerivedFactorComponent> findByInputFactorId(@Param("inputFactorId") Long inputFactorId);
//
//    /**
//     * 根据衍生因子ID和输入因子ID查找组件
//     */
//    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.id = :derivedFactorId AND dfc.inputFactor.id = :inputFactorId")
//    Optional<DerivedFactorComponent> findByDerivedFactorIdAndInputFactorId(@Param("derivedFactorId") Long derivedFactorId, @Param("inputFactorId") Long inputFactorId);
//
//    /**
//     * 根据衍生因子ID删除所有组件
//     */
//    @Query("DELETE FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.id = :derivedFactorId")
//    void deleteByDerivedFactorId(@Param("derivedFactorId") Long derivedFactorId);
//
//    /**
//     * 根据衍生因子ID统计组件数量
//     */
//    @Query("SELECT COUNT(dfc) FROM DerivedFactorComponent dfc WHERE dfc.derivedFactor.id = :derivedFactorId")
//    long countByDerivedFactorId(@Param("derivedFactorId") Long derivedFactorId);
//
//    /**
//     * 根据操作类型查找组件
//     */
//    List<DerivedFactorComponent> findByOperationType(OperationType operationType);

    /**
     * 根据权重范围查找组件
     */
    @Query("SELECT dfc FROM DerivedFactorComponent dfc WHERE dfc.weight BETWEEN :minWeight AND :maxWeight")
    List<DerivedFactorComponent> findByWeightBetween(@Param("minWeight") BigDecimal minWeight,
                                                    @Param("maxWeight") BigDecimal maxWeight);

    /**
     * 根据衍生因子删除所有组件
     */
    void deleteByDerivedFactor(org.abc.fund.entity.factorEntity.DerivedFactor derivedFactor);
}